//162
class Solution {
    public int findPeakElement(int[] nums) {
        int left = 0;
        int right = nums.length - 2;
        while(left <= right){
            int mid = left + (right - left) / 2;
            if(nums[mid] > nums[mid + 1]){
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        return right + 1;
    }
}
//34
class Solution {
    public int lowerbounds(int[] nums,int target) {
        int left = 0;
        int right = nums.length - 1;//[left,right]
        while(left <= right){//要满足集合不为空
            int mid = left + (right - left)/2;
            if(nums[mid] >= target){
                right = mid - 1; //[left,mid-1]
            }else{
                left = mid + 1;//[mid+1,right]
            }
        }
        return left;//right+1
    }
    public int lowerbounds1(int[] nums, int target){
        int left = -1;
        int right = nums.length;//(left,right)
        while(left+1 < right){
            int mid = left + (right-left)/2;
            if(nums[mid] < target){
                left = mid;//(mid,right)
            }else{
                right = mid;//(left,mid)
            }
        }
        return left+1;//right
    }
    public int lowerbounds2(int[] nums, int target){
        int left = 0;
        int right = nums.length;//[left,right)
        while(left < right){//
            int mid = left + (right - left)/2;
            if(nums[mid]<target){
                left = mid+1;//[mid+1,right)
            }else{
                right = mid;//[left,mid)
            }
        }
        return left;//right
    }
    public int lowerbounds3(int[] nums, int target){
        int left = -1;
        int right = nums.length-1;//(left,right]
        while(left < right){
            int mid = left + (right - left +1)/2;
            if(nums[mid] < target){
                left = mid;//(mid,right]
            }else{
                right = mid - 1;//(left,mid-1]
            }
        }
        return left + 1;//right+1
    }
    public int[] searchRange(int[] nums, int target) {
        int start = lowerbounds3(nums,target);
        int end;
        if(start == nums.length || nums[start] != target){
            return new int[]{-1,-1};
        }else{
            end = lowerbounds3(nums,target+1)-1;
        }
        return new int[]{start,end};
    }
}
public class Tesr {
}
